<?php 
require_once '../includes/funciones.php';
conexion();
require_once 'seguridad.php';

if($_POST['boton']==1)
{
    if(isset($_POST['date']) && !empty($_POST['date']) && isset($_POST['title']) && !empty($_POST['title']) && isset($_POST['description']) && !empty($_POST['description'])) 
        {
            $date=cambiarFechaBase($_POST['date']);
            $title=$_POST['title'];
            $description=$_POST['description'];
            $published=$_POST['published'];
		
            $campos="title, description, date, is_published";
            
            $valores="'$title','$description','$date',$published";
            
            mysql_query("INSERT INTO events (title,description,date,is_published,user_id) VALUES ('$title','$description','$date','$published','{$_SESSION["usuario"]["idusuario"]}')");
            
            header("Location: eventos.php");$_SESSION["errorcargarevento"] = "cargo";
            header("Location: eventos.php");
        
        }
        else
        {
            
	$_SESSION["errorcargarevento"] = "falta";
	header("Location: cargar_evento.php");
 	}
}

if($_POST['boton']== 2){
	 
	$id_events=sqlint($_POST['id_events']);#valor hidden de modificar_eventos
	$publishedbd=sqlint($_POST['publishbd']);#valor hidden de modificar eventos
	$date=cambiarFechaBase($_POST['date']);
	$title=sqlstring(cleanxss($_POST['title']));
	$description=sqlstring(cleanxss($_POST['description']));
	$published=sqlint($_POST['published']);//Variable checkbox de POST. Si quiere o no publicar.
	
        mysql_query("UPDATE events SET user_id='{$_SESSION["usuario"]["idusuario"]}', date='$date', title='$title', description='$description', is_published=$published WHERE id=$id_events ") or die (mysql_error()); 
       
        $_SESSION["errormodificarevento"] = "correcto";
	header("Location: eventos.php");
        
}
        
if($_POST['boton'] == 3)
{
    $id_events=sqlint($_POST['id_events']); #valor hidden de modificar_eventos
    
    sqldelete("events", "id", $id_events);
    $_SESSION["errorborrarevento"]="correcto";
    header("Location: eventos.php");
	  
}

?>